package main

import (
	"fmt"
	"os"
	"path/filepath"
	"runtime"
	"sale-admin/internal/models"

	"github.com/spf13/cobra"
	"gorm.io/gen"
)

var modelNameInput string

func init() {
	rootCmd.PersistentFlags().StringVarP(&modelNameInput, "model", "m", "", "talbe struct name")
}

func main() {
	Execute()
}

func Execute() {
	if err := rootCmd.Execute(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}

// Dao层代码生成 old
var rootCmd = &cobra.Command{
	Use:   "daogen",
	Short: "daogen",
	Run: func(*cobra.Command, []string) {
		_, filename, _, _ := runtime.Caller(0)
		g := gen.NewGenerator(gen.Config{
			OutPath: filepath.Dir(filename) + "/../internal/dal/",
			Mode:    gen.WithDefaultQuery | gen.WithQueryInterface, // generate mode
		})
		g.ApplyBasic(models.Models...)
		g.Execute()
	},
}
